版权声明:本文为博主原创文章,未经博主允许不得转载。如文章对您有帮助,欢迎扫描上面或者头像上的二维码支持,谢谢~ https://blog.csdn.net/b2222505/article/details/78878626
一、 PandoraBootstrap.run
获取当前AppClassLoader的urls(JDK系统jar包、本地maven仓库jar包、业务系统classes文件夹)
生成一个ReLaunchURLClassLoader,也称为bizClassLoader(URLClassLoader类型。构造函数传入urls、parent为AppClassLoader)
创建sar包Archive(本质为一个JarFile)
二、 PandoraContainer 类初始化
- PipelineContext :保存sar的url、plugin url
- ClassLoaderHolder :保存bizClassLoader
- ServiceContainer :IOC容器(picocontainer),创建并设置类依赖(DeployService、PluginModuleFactory、ClassLoaderService、SharedClassService、HostInfoService、Pipeline、Context、PandoraServiceManager、InitializerChecker、ClassExporter、LifecycleService、RegistryService)
三、 PandoraContainer 调用start方法
- ServiceContainer 初始化并注入类依赖关系
- Pipeline 初始化 :根据 pipeline.properties 组装任务链表
- 调用 Pipeline 的 execute 方法。按顺序执行pipeline下的类的stepIn和stepOut方法。
## From top to bottom out
## ======================== DEPLOYING ======================== ##
Log4jDefaultInitOverride=com.taobao.pandora.stage.Log4jDefaultInitOverride
MergeFolderPlugin=com.taobao.pandora.stage.MergeFolderPlugin
DeployPluginModule=com.taobao.pandora.stage.DeployPluginModule
InitializerCheck=com.taobao.pandora.stage.InitializerCheck
ExportClass2Cache=com.taobao.pandora.stage.ExportClass2Cache
RegisterPandoraService=com.taobao.pandora.stage.RegisterPandoraService
RegisterLifecycleListener=com.taobao.pandora.stage.RegisterLifecycleListener
## ======================== DEPLOYED ======================== ##
ChangeStateDeployed=com.taobao.pandora.stage.ChangeStateDeployed
StartPandoraService=com.taobao.pandora.stage.StartPandoraService
MergeFolderPlugin
合并Plugin,并存储到PipelineContext中。(com.taobao.pandora.plugins.ext_path > pluginUrls > sar包里plugins)
DeployPluginModule
通过DeployService发布所有Plugin模块 。
给定一个模块目录,根据目录中配置文件生成 ModuleClassLoader ,构建PluginModule。
- priority.properties
- version.properties
- import.properties
- export.properties
- initializer.properties
- service.properties
- listener.properties
InitializerCheck
调用每个module的initializer的permitStartup方法
ExportClass2Cache
用module各自的ModuleClassLoader导出ExportInfo的jarList、packageList、classesList的class到sharedClassService中。
RegisterPandoraService
每个module新建一个PandoraServiceWrapper并调用init方法(service.properties)
RegisterLifecycleListener
每个module注册pluginListeners(listener.properties)。目前没中间件会配置。
ChangeStateDeployed
每个module的状态更改为DEPLOYED
StartPandoraService
每个module新建一个PandoraServiceWrapper并调用start方法。
ModuleClassLoader的加载过程
- 已经加载的类
- 加载JDK相关的类
- com.taobao.pandora开头的选择从PandoraClassLoader中加载
- 从共享缓存加载
- 根据import语义从bizClassLoader中加载
- 从当前classpath下加载
- 从bizClassLoader中加载
- 从SystemClassLoader下加载
类结构图

参考资料
http://blog.csdn.net/b2222505/article/details/78806252
https://bingoex.github.io/2015/09/17/jvm-book-3-classloader/